import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_module/common/base/base_page.dart';
import 'package:flutter_module/playgroound/playground_router.dart';

/// Create by kyluzoi
/// Date: 2021-08-16
///
/// Description: 项目实验室 page

class PlaygroundPage extends BaseStatelessWidget {
  var items = [
    ItemVo(content: "Toast实验室", routerPath: PlaygroundRouter.TOAST),
    ItemVo(content: "骨架屏实验室", routerPath: PlaygroundRouter.SKELETON),
    ItemVo(content: "指示器", routerPath: PlaygroundRouter.INDICATOR),
    ItemVo(content: "空态图", routerPath: PlaygroundRouter.EMPTYVIEW),
    ItemVo(
        content: '合作服务商编辑', routerPath: PlaygroundRouter.serviceProviderEdit),
  ];

  @override
  Widget createView(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(
          onPressed: () {
            // Navigator.pop(context);
          },
        ),
        title: Text("实验室工厂"),
      ),
      body: _createContentView(context),
    );
  }

  _createContentView(BuildContext context) {
    return ListView.builder(
        itemCount: items.length,
        itemBuilder: (context, index) {
          return ItemView(
              item: items[index],
              onPress: () {
                Navigator.pushNamed(context, items[index].routerPath!);
              });
        });
  }
}

class ItemVo {
  String content;
  String? routerPath;
  Function()? itemClick;

  ItemVo({required this.content, this.routerPath, this.itemClick});
}

class ItemView extends BaseStatelessWidget {
  final ItemVo item;
  final Function() onPress;

  const ItemView({Key? key, required this.item, required this.onPress})
      : super(key: key);

  @override
  Widget createView(BuildContext context) {
    return GestureDetector(
      onTap: onPress,
      child: Card(
          child: Container(
        height: 100.rpx,
        child: Center(child: Text(item.content)),
      )),
    );
  }
}
